<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="Username" />

    <MyPerson :list="renderList" @particulars="particulars" />
    <my-particulars
      v-show="flag"
      :useritem="useritem"
      @close="particulars"
    ></my-particulars>
  </div>
</template>
<script>
import MyPerson from './components/MyPerson.vue'
import MyParticulars from '@/components/MyParticulars.vue'
export default {
  components: {
    MyPerson,
    MyParticulars,
  },

  data() {
    return {
      list: [
        {
          time: '2020 - 12 - 12',
          uname: '张三',
          result: '健康',
          message: '无',
        },
        {
          time: '2020 - 12 - 12',
          uname: '李四',
          result: '头疼',
          message: '止痛药',
        },
        {
          time: '2020 - 12 - 12',
          uname: '王五',
          result: '骨折',
          message: '住院',
        },
      ],
      Username: '',
      flag: false,
      useritem :{}
    }
  },
  methods: {
    particulars(item) {
      this.flag = !this.flag
     item ?  this.useritem = item : ''
    },
  },

  computed: {
    renderList() {
      return this.list.filter((item) => {
        return (
          item.time.includes(this.Username) ||
          item.uname.includes(this.Username) ||
          item.result.includes(this.Username) ||
          item.message.includes(this.Username)
        )
      })
    },
  },
}
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
